package cn.hl.sfzy.controller;

import cn.hl.sfzy.entity.Charge;
import cn.hl.sfzy.service.impl.ChargeServiceImpl;
import cn.hl.sfzy.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Date 2024年10月23日
 */
//取消所有黄色警告
//@SuppressWarnings("all")
@RestController
@RequestMapping("/charge")
public class ChargeController {
    @Autowired
    private ChargeServiceImpl chargeService;

    /**
     * 添加
     */
    @PostMapping("/add")
    public Result add(@RequestBody Charge charge) {
        chargeService.add(charge);
        return Result.success("添加成功");
    }

    /**
     * 删除
     */
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable("id") Long id) {
        Long[] ids = {id};
        chargeService.remove(ids);
        return Result.success("删除成功");
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/removeBatch")
    public Result removeBatch(Long[] ids) {
        chargeService.remove(ids);
        return Result.success("删除成功");
    }

    /**
     * 修改
     */
    @PutMapping("/edit")
    public Result edit(@RequestBody Charge charge) {
        chargeService.edit(charge);
        return Result.success("修改成功");
    }

    /**
     * id查询
     */
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable("id") Long id) {
        Charge charge = new Charge();
        charge.setId(id);
        List<Charge> list = chargeService.find(charge);
        return Result.success(list);
    }

    /**
     * 查询所有
     */
    @GetMapping("/findAll")
    public Result findAll() {
        List<Charge> list = chargeService.find(null);
        return Result.success(list);
    }

    /**
     * 查询
     */
    @GetMapping("/find")
    public Result find(@RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       Charge charge) {
        PageInfo<Charge> data = findByPage(pageNum, pageSize, charge);
        return Result.success(data);

    }


    /**
     * 分页查询
     */
    @GetMapping("/findByPage")
    public PageInfo<Charge> findByPage(int pageNum, int pageSize, Charge charge) {
        return chargeService.findByPage(pageNum, pageSize, charge);
    }
}
